#include <stdio.h>
struct friend
{
    char name[51], phone[51];
    int time;
}f[11];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%s %d %s", f[i].name, &f[i].time, f[i].phone);
    }
    for(int i = 1; i <= n; i++)
    {
        int index = i;
        for(int j = i; j <= n; j++)
        {
            if(f[j].time < f[index].time) index = j;
        }
        struct friend tmp;
        tmp = f[i];
        f[i] = f[index];
        f[index] = tmp;
    }
    for(int i = 1; i <= n; i++)
    {
        printf("%s %d %s\n", f[i].name, f[i].time, f[i].phone);
    }
    return 0;
}